/* 全局过滤器 函数 */

//处理时间格式 Ymd 年月日
export const formatDateYmd = (time) => {
    let date = new Date(time)
    let Y = date.getFullYear();
    let m = date.getMonth() + 1;
    let d = date.getDate()
    return [Y, m, d].map(v => String(v).padStart(2, '0')).join('/')
}

//处理时间格式 YmdHms 年月日 时分秒
export const formatDateYmdHms = (time) => {
    let date = new Date(time)
    let y = date.getFullYear();
    let M = date.getMonth() + 1;
    let d = date.getDate()

    let h = date.getHours()
    let m = date.getMinutes()
    let s = date.getSeconds()
    return [y, M, d].map(v => String(v).padStart(2, '0')).join('/') + ' ' + [h, m, s].map(v => String(v).padStart(2, '0')).join(':')
}

//处理时间格式 Hms 时分秒
export const formatDateHms = (time) => {
    let date = new Date(time)

    let h = date.getHours()
    let m = date.getMinutes()
    let s = date.getSeconds()
    return [h, m, s].map(v => String(v).padStart(2, '0')).join(':')
}

//超过1000 补逗号
export const thousandSeparator = (num) => num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')